home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / pascal / dlgdsn41.zip / CPPSRC2.CPP < prev    next >
C/C++ Source or Header  |  1993-12-12  |  19KB  |  746 lines

  1. /*Substitutions and fills in file, cppskel.dat
  2.  
  3.   Area Fills
  4.   @ZZ0    Form the dialog in constructor
  5.   @ZZ1    Defined Control Names in Object Def.
  6.   @ZZ2    Data struct def
  7.   @ZZ3    Variable names in 'read'
  8.   @ZZ4    Variable names in 'write'
  9.   @ZZ5    Ancestor constructor call
  10.   @ZZ6    Uses_ stuff
  11.   @ZZ7    include of tcolortx.h, tinplong.h
  12.   @ZZ8    Links
  13.  
  14.   Substitutions
  15.   @XX1    Dialog's Symbol   (as  TMyDialog)
  16.   @XX2    Dialog's ancestor (usually TDialog)
  17.   @XX3    Dialog's registration TStreamRec (as RMyDialog)
  18.   @XX4    Filename (upper case)
  19.   @XX5    Filename (lower case)
  20. */
  21.  
  22. #define Uses_TStringCollection
  23. #include <tv.h>
  24. #include <stdlib.h>
  25. #include <dos.h>
  26. #include <dir.h>
  27. #include <fcntl.h>
  28. #include <string.h>
  29. #include <iostream.h>
  30. #include <fstream.h>
  31. #include <stdio.h>
  32. #include "readscpt.h"
  33.  
  34. ofstream outf;
  35. ifstream data;
  36. #define BIG 300
  37. char s[BIG], upperName[MAXFILE], lowerName[MAXFILE];
  38. Boolean needcontrol1 = False;
  39.  
  40. char* quoted(const char* s)
  41. //if the first char of s is '@', assumes a variable wanted and strips the '@'
  42. //else returns a double quoted string or 0 for empty string
  43. {
  44.  static char q[300];
  45.  if (s[0] == '@')
  46.    {strcpy(q, &s[1]);
  47.     return q;
  48.    }
  49.  strcpy(q, "\"");   //the first quote in place
  50.  if (*s == '\0' || !s) return "0";
  51.  strcat(q, s);
  52.  short l = strlen(q);
  53.  q[l] = '\"';
  54.  q[l+1] = '\0';
  55.  return q;
  56. }
  57.  
  58. void aField(ViewObj *P, char* fieldtype)
  59. {
  60.  outf << "  " << fieldtype << " " << P->FieldName << ";   //" << P->Obj <<endl;
  61. }
  62. void aVar(ViewObj *P)
  63. {
  64.  if (strcmp(P->VarName, "control") != 0)
  65.    outf << "    " << P->Obj << " *" << P->VarName << ";\n";
  66. }
  67.  
  68. //the following extend the ViewObj struct's to also write the code
  69. struct DialogWriteObj : DialogObj {
  70.      virtual void writeCode();
  71.      };
  72.  
  73. struct ButtonWriteObj : ButtonObj {
  74.      virtual void writeCode();
  75.      virtual void writeVars() {aVar(this);};
  76.      };
  77.  
  78. struct InputLongWriteObj : InputLongObj {
  79.      virtual void writeCode();
  80.      virtual void writeFields() {aField(this, "long");} ;
  81.      virtual void writeVars() {aVar(this);};
  82.      };
  83. struct LabelWriteObj : LabelObj {
  84.      virtual void writeCode();
  85.      };
  86. struct HistoryWriteObj : HistoryObj {
  87.      virtual void writeCode();
  88.      };
  89. struct InputLineWriteObj : InputLineObj {
  90.      virtual void writeCode();
  91.      virtual void writeFields();
  92.      virtual void writeVars() {aVar(this);};
  93.      };
  94. struct ClusterWriteObj : ClusterObj {
  95.      virtual void writeCode();
  96.      virtual void writeFields() {aField(this, "ushort");} ;
  97.      virtual void writeVars() {aVar(this);};
  98.      };
  99. struct ListBoxWriteObj : ListBoxObj {
  100.      virtual void writeCode();
  101.      virtual void writeFields() {aField(this, "TListBoxRec");} ;
  102.      virtual void writeVars() {aVar(this);};
  103.      };
  104. struct ScrollBarWriteObj : ScrollBarObj {
  105.      virtual void writeCode();
  106.      virtual void writeVars();
  107.      };
  108. struct MemoWriteObj : MemoObj {
  109.      virtual void writeCode();
  110.      virtual void writeFields();
  111.      virtual void writeVars() {aVar(this);};
  112.      };
  113. struct StaticTextWriteObj : StaticTextObj {
  114.      virtual void writeCode();
  115.      virtual void writeVars() {aVar(this);};
  116.      };
  117. struct ColoredTextWriteObj : ColoredTextObj {
  118.      virtual void writeCode();
  119.      virtual void writeVars() {aVar(this);};
  120.      };
  121.  
  122.  
  123.  
  124. //now that we know the final extensions of ViewObj, we can write the
  125. //getKind function
  126. ViewObj *getKind(recType Kind)
  127. { ViewObj *P;
  128.   switch (Kind) {
  129.       case Dlg : P = new DialogWriteObj(); break;
  130.       case Button : P = new ButtonWriteObj(); break;
  131.       case InputL : P = new InputLineWriteObj(); break;
  132.       case Labl : P = new LabelWriteObj();  break;
  133.       case Histry : P = new HistoryWriteObj(); break;
  134.       case ILong : P = new InputLongWriteObj(); break;
  135.       case CheckB: P = new ClusterWriteObj(); break;
  136.       case RadioB: P = new ClusterWriteObj(); break;
  137.       case MultiCB: P = new MultiCheckBoxObj(); break;
  138.       case ListB: P = new ListBoxWriteObj(); break;
  139.       case ScrollB :  P = new ScrollBarWriteObj(); break;
  140.       case Memo: P = new MemoWriteObj(); break;
  141.       case SText: P = new StaticTextWriteObj(); break;
  142.       case CText : P = new ColoredTextWriteObj(); break;
  143.       default : P = 0; break;
  144.       }
  145. return P;
  146. }
  147.  
  148. char * getWinFlagWords(ushort w, char *s)
  149. //given the set bits return names in 'or' form
  150. {
  151.  static char *flagArray[4] =  {
  152.     "wfMove", "wfGrow", "wfClose", "wfZoom"};
  153.  s[0] = '\0';
  154.  for (int i = 0; i <= 3; i++) {
  155.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  156.      strcat(strcat(s, flagArray[i]), " | ");
  157.    w >>= 1;
  158.    }
  159.  int l = strlen(s);
  160.  if (l > 4)
  161.     s[l-3] = '\0';   //remove last " | "
  162.  return s;
  163. }
  164.  
  165. char * getEventWords(ushort w, char *s)
  166. //given the set bits return names in 'or' form
  167. {
  168.  static char *flagArray[16] =  {
  169.         "evMouseDown", "evMouseUp", "evMouseMove", "evMouseAuto",
  170.     "evKeyDown", "0x20", "0x40", "0x80", "evCommand", "evBroadcast",
  171.     "0x400", "0x800", "0x1000", "0x2000", "0x4000", "0x8000"};
  172.  s[0] = '\0';
  173.  for (int i = 0; i <= 15; i++) {
  174.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  175.      strcat(strcat(s, flagArray[i]), " | ");
  176.    w >>= 1;
  177.    }
  178.  int l = strlen(s);
  179.  if (l > 4)
  180.     s[l-3] = '\0';   //remove last " | "
  181.  return s;
  182. }
  183.  
  184. char * getOptionWords(ushort w, char *s)
  185. //given the set bits return names in 'or' form
  186. {
  187.  static char *flagArray[16] =  {
  188.         "ofSelectable", "ofTopSelect", "ofFirstClick", "ofFramed",
  189.         "ofPreProcess", "ofPostProcess", "ofBuffered", "ofTileable",
  190.         "ofCenterX", "ofCenterY", "ofValidate", "0x800", "0x1000",
  191.         "0x2000", "0x4000", "ofShoehorn"};
  192.  s[0] = '\0';
  193.  for (int i = 0; i <= 15; i++) {
  194.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  195.      strcat(strcat(s, flagArray[i]), " | ");
  196.    w >>= 1;
  197.    }
  198.  int l = strlen(s);
  199.  if (l > 4)
  200.     s[l-3] = '\0';   //remove last " | "
  201.  return s;
  202. }
  203.  
  204. short bitCount(ushort w) //numbers of set bits in the word
  205. {
  206.  short count = 0;
  207.  for (int i = 0; i <= 15; i++)  {
  208.     if ((w & 1) == 1)
  209.        count++;
  210.     w >>= 1;
  211.     }
  212. return count;
  213. }
  214.  
  215. void doBitOutput(const char* var, const char* pre, ushort actual,
  216.                        ushort defaul, char* (func)(ushort w, char* s))
  217. //output something like "foo->options |= ofSelectable or ofFramed;"
  218. //and/or "foo-> options &= ofTopSelect;"
  219. //actual is the bits set and defaul are the default settings
  220. //it's known that actual and defaul are not equal on entry
  221. {
  222.  char s[100];
  223.  ushort NOTs, ORs, diff ;
  224.  diff = actual ^ defaul;  //the bits that are different
  225.  if (bitCount(diff) > 5) { //this is too complex--output hex number
  226.    outf << " " << var << pre << " = 0x" << hex << actual << dec <<";\n";
  227.    return;
  228.    }
  229.  NOTs = diff & defaul;  //the bits not in defaul
  230.  ORs = diff & actual;    //the extra bits in actual
  231.  s[0] = '\0';
  232.  if (NOTs != 0) {
  233.    outf << " " << var <<pre;
  234.    if (bitCount(NOTs) == 1)
  235.      outf << " &= ~" << func(NOTs, s) << ";\n";
  236.    else
  237.      outf << " &= ~(" << func(NOTs, s) << ");\n";
  238.    }
  239.  s[0] = '\0';
  240.  if (ORs != 0)
  241.    outf << " " << var << pre << " |= " << func(ORs, s) << ";\n";
  242. }
  243.  
  244. void doTRect(ViewObj *P)
  245. {
  246. outf << "(TRect(" << P->X1 << ", " << P->Y1 << ", "
  247.      << P->X2 << ", " << P->Y2 << ")";
  248. }
  249.  
  250. void insertControl(const char *Name)
  251. {
  252.  outf <<  " insert(" << Name << ");\n\n";
  253. }
  254.  
  255. void doOpEvent(ViewObj *P)
  256. {if (P->DefEvMsk != P->EvMsk)
  257.    doBitOutput(P->VarName, "->eventMask", P->EvMsk, P->DefEvMsk, getEventWords);
  258.  
  259. if (P->DefOptns != P->Optns)
  260.    doBitOutput(P->VarName, "->options", P->Optns, P->DefOptns, getOptionWords);
  261.  
  262. }
  263.  
  264. void writeHelpCtx(char * VarName, char* H, ushort Ctx)
  265. {
  266. if (*H != '\0') {
  267.   if (strcmp(H, "hcNoContext")) {
  268.     outf << " " << VarName << "->helpCtx = " << H << ";\n";
  269.     }
  270.   }
  271. else if (Ctx != 0) {
  272.     outf << " " << VarName << "->helpCtx = " << Ctx << ";\n";
  273.     }
  274. }
  275.  
  276. void start(ViewObj *P)
  277. {
  278.   outf << " " << P->VarName << " = new " << P->Obj;
  279.   doTRect(P);
  280. }
  281.  
  282. void finish(ViewObj *P)
  283. {
  284.  writeHelpCtx(P->VarName, P->HelpCtxSym, P->HCtx);
  285.  doOpEvent(P);
  286.  insertControl(P->VarName);
  287. }
  288.  
  289. void flagsOut(ushort flags)
  290. {
  291.  if (flags == 0) outf << "bfNormal";
  292.  else {
  293.     short plus = 0;
  294.     if ((flags & 1) != 0) {
  295.         plus = 1; outf << "bfDefault"; }
  296.     if ((flags & 2) != 0) {
  297.         if (plus) outf << "|";
  298.         plus = 1;
  299.         outf << "bfLeftJust";}
  300.     if ((flags & 4) != 0) {
  301.         if (plus) outf << "|";
  302.         plus = 1;
  303.         outf << "bfBroadcast"; }
  304.     if ((flags & 8) != 0)  {
  305.         if (plus) outf << "|";
  306.         outf << "bfGrabFocus"; }
  307.     }
  308. }
  309.  
  310. void ButtonWriteObj::writeCode()
  311. {
  312.  start(this);
  313.  outf << ", " << quoted(ButtonText) << ", ";
  314.  if (*CommandName != '\0')
  315.     outf << CommandName;
  316.  else outf << CommandValue;
  317.  outf << ", ";
  318.  flagsOut(Flags);
  319.  outf << ");\n";
  320.  finish(this);
  321. }
  322.  
  323. void LabelWriteObj::writeCode()
  324. {
  325.  outf << "   insert(new " << Obj;
  326.  doTRect(this);
  327.  outf << ", " << quoted(LabelText) << ", " << LinkName << "));\n\n";
  328. }
  329.  
  330. void HistoryWriteObj::writeCode()
  331. {
  332.  outf << "   insert(new " << Obj;
  333.  doTRect(this);
  334.  outf << ", (TInputLine*)" << HistoryLink << ", " << HistoryID << "));\n\n";
  335. }
  336.  
  337. void InputLongWriteObj::writeCode()
  338. {
  339.   start(this);
  340.   outf << ", " << (LongStrLeng+1) << ", " << LLim << ", " << ULim <<  ", "
  341.        << ILOptions << ", " << quoted(LongLabelText) << ");\n";
  342.   finish(this);
  343. }
  344.  
  345. void InputLineWriteObj::writeCode()
  346. {
  347.   start(this);
  348.   outf << ", " << (StringLeng+1) << ");\n";    //Note: add 1
  349.   finish(this);
  350. }
  351. void InputLineWriteObj::writeFields()
  352. {
  353.   outf << "  char " << FieldName << "[" << (StringLeng+1)  //Note: add 1 !
  354.        << "];   //" << Obj << endl;
  355. }
  356.  
  357. void doAtText(char *s)  // an '@' reference string
  358. {
  359.  while (*s) {
  360.    char c = *s++;
  361.    switch (c) {
  362.      case 0x3 :
  363.      case '@': break;
  364.      case '\\' :
  365.        if (*s == 'n') s++;
  366.        else outf << c;
  367.        break;
  368.      default : outf << c;
  369.      }
  370.   }
  371. }
  372.  
  373. void doText(char *s)
  374. {    //split up a long string into several lines. String cannot exceed 254
  375.  if (!*s) {
  376.    outf << 0;
  377.    return;
  378.    }
  379.  if (strlen(s) > 254) s[254] = '\0';   //truncate if too big
  380.  outf << '\"';
  381.  short count = 47;
  382.  while (*s)  {
  383.     if (s[0] == '\\' && s[1] == 'n' && s[2]) {
  384.        outf << s[0] << s[1] << "\"\n     \"";
  385.        count = 5;
  386.        s++;    //extra increment to pass 'n'
  387.        }
  388.     else {
  389.        outf << *s;
  390.        count++;
  391.        }
  392.     s++;
  393.     if (count > 75 && *s) {
  394.        outf << "\"\n     \"";
  395.        count = 5;
  396.        }
  397.     }
  398.  outf << '\"';
  399. }
  400.  
  401. void StaticTextWriteObj::writeCode()
  402. {
  403.   start(this);
  404.   outf << ", ";
  405.   if(Text[0] == '@' || Text[0] == 3 && Text[1] == '@')
  406.     doAtText(Text);
  407.   else
  408.     doText(Text);
  409.   outf << ");\n";
  410.   finish(this);
  411. }
  412.  
  413. void ColoredTextWriteObj::writeCode()
  414. {
  415.   start(this);
  416.   outf << ", ";
  417.   if(Text[0] == '@' || Text[0] == 3 && Text[1] == '@')
  418.     doAtText(Text);
  419.   else
  420.     doText(Text);
  421.   outf << ", 0x" << hex << Attrib << dec << ");\n";
  422.   finish(this);
  423. }
  424.  
  425. void ScrollBarWriteObj::writeCode()
  426. {
  427.   start(this);
  428.   outf << ");\n";
  429.   finish(this);
  430. }
  431.  
  432. void ScrollBarWriteObj::writeVars()
  433. {
  434.  if (strcmp(VarName, "control1") != 0) //control1 is used by TMemo
  435.    aVar(this);
  436.  else needcontrol1 = True;
  437. }
  438.  
  439. void ListBoxWriteObj::writeCode()
  440. {
  441.   start(this);
  442.   outf << ", " << Columns << ", ";
  443.   if (*ScrollBar != '\0')
  444.     outf << "(TScrollBar*)" << ScrollBar << ");\n";
  445.   else outf << "0);\n";
  446.   finish(this);
  447. }
  448.  
  449. void MemoWriteObj::writeCode()
  450. {
  451.   start(this);
  452.   outf << ", " ;
  453.   if (*HScroll != '\0')
  454.     outf << "(TScrollBar*)" << HScroll << ", ";
  455.   else outf << "0, ";
  456.   if (*VScroll != '\0')
  457.     outf << "(TScrollBar*)" << VScroll << ", 0, ";
  458.   else outf << "0, 0, ";
  459.   outf << BufSize << ");\n";
  460.   finish(this);
  461. }
  462. void MemoWriteObj::writeFields()
  463. {
  464.   outf << "  ushort " << FieldName << ";   //" << Obj << " text length\n";
  465.   outf << "  char " << TextFieldName << "[" << BufSize << "];   //"
  466.        << Obj << " text\n";
  467. }
  468.  
  469. void ClusterWriteObj::writeCode()
  470. {
  471.   start(this);
  472.   for (int i=0; i < Items; i++)
  473.     outf << ",\n  new TSItem(\"" << (char *)LabelColl->at(i) << "\"";
  474.   outf << ", 0";
  475.   for (i = 0; i <= Items; i++)
  476.     outf << ")";
  477.   outf << ";\n";
  478.   finish(this);
  479. }
  480.  
  481. void DoControls(void *p, void*)
  482. {ViewObj *P = (ViewObj*)p;
  483.  P->writeCode();
  484. }
  485.  
  486. void DialogWriteObj::writeCode()
  487. {
  488.   outf << " TView *control";
  489.   if (needcontrol1) outf << ", *control1;\n";
  490.   else outf << ";\n";
  491.  
  492.   if (DefEvMsk != EvMsk)
  493.      doBitOutput("", "eventMask", EvMsk, DefEvMsk, getEventWords);
  494.  
  495.   if (DefOptns != Optns)
  496.      doBitOutput("", "options", Optns, DefOptns, getOptionWords);
  497.  
  498.   if (WinFlags != 5)    //5 is the default
  499.      doBitOutput("", "flags", WinFlags, 5, getWinFlagWords);
  500.   writeHelpCtx("this", HelpCtxSym, HCtx);                //!! needs work !!
  501.   outf << endl;
  502.  
  503.   ScriptColl->forEach(DoControls, 0);
  504. }
  505.  
  506. char* SkelDatName(char *exe, char* rtn)
  507. //find where to locate cppskel.dat.  Use drive, directory of this exe file
  508. {
  509.  char drive[MAXDRIVE];
  510.  char dir[MAXDIR];
  511.  char name[MAXFILE];
  512.  char ext[MAXEXT];
  513.  fnsplit(exe, drive, dir, name, ext);
  514.  fnmerge(rtn, drive, dir, "CPPSKEL", ".DAT");
  515.  return rtn;
  516. }
  517.  
  518. void subst(char *p) //make a substitution for @XXn
  519. {
  520. char tail[BIG];
  521. short n = *(p+3) - '0';    //get the @XX #
  522. *p = '\0';                 //terminate s at the '@'
  523. strcpy(tail, p+4);         //keep the rest of the line
  524. switch (n) {
  525.   case 1 :                //this would be @XX1
  526.        strcat(s, Dialog->Obj);
  527.        strncat(s, tail, BIG-strlen(s));
  528.        break;
  529.   case 2 :
  530.        strcat(s, "TDialog");
  531.        strncat(s, tail, BIG-strlen(s));
  532.        break;
  533.   case 3 :
  534.        strcat(s, "R");            //subst 'R' for 'T'
  535.        strcat(s, Dialog->Obj+1);  //less the 'T'
  536.        strncat(s, tail, BIG-strlen(s));
  537.        break;
  538.   case 4 :
  539.        strcat(s, upperName);
  540.        strncat(s, tail, BIG-strlen(s));
  541.        break;
  542.   case 5 :
  543.        strcat(s, lowerName);
  544.        strncat(s, tail, BIG-strlen(s));
  545.        break;
  546.   }
  547. }
  548.  
  549. void doWriteItems(void *p, void* first)
  550. {
  551.  ViewObj *P = (ViewObj*)p;
  552.  if (*P->VarName != '\0' && strcmp(P->VarName, "control") != 0
  553.                  && strcmp(P->VarName, "control1") != 0) {
  554.     if (*(int*)first)  {
  555.        outf << " os";
  556.        *(int*)first = False;
  557.        }
  558.     outf << " << " << P->VarName;
  559.     }
  560. }
  561.  
  562. void doTheWriteItems()
  563. {//code to Write pointers in 'Write'
  564.  int first = True;
  565.  ScriptColl->forEach(doWriteItems, &first);
  566.  if (!first) outf << ";\n";  //if !first, there is at least one item
  567. }
  568.  
  569. void doReadItems(void *p, void* first)
  570. {
  571.  ViewObj *P = (ViewObj*)p;
  572.  if (*P->VarName != '\0' && strcmp(P->VarName, "control") != 0
  573.                  && strcmp(P->VarName, "control1") != 0) {
  574.     if (*(int*)first)  {
  575.        outf << " is";
  576.        *(int*)first = False;
  577.        }
  578.     outf << " >> " << P->VarName;
  579.     }
  580. }
  581.  
  582. void doTheReadItems()
  583. {//code to read pointers in 'read'
  584.  int first = True;
  585.  ScriptColl->forEach(doReadItems, &first);
  586.  if (!first) outf << ";\n";  //if !first, there is at least one item
  587. }
  588.  
  589. void doFields(void *p, void* first)
  590. {     // fieldnames for the data transfer struct
  591.  ViewObj *P = (ViewObj*)p;
  592.  if (*(int*)first && *P->FieldName != '\0') {
  593.     outf << "struct " << Dialog->FieldName << "  {\n";
  594.     *(int*)first = False;
  595.     }
  596.  P->writeFields();
  597. }
  598.  
  599. void doTheDataStruct()
  600. {//code to build the data transfer struct
  601.  if (Dialog->FieldName[0])  {  //no fieldname, no datarecord
  602.    if (present[ListB])   //if we have listbox, define TListBoxRec
  603.       outf <<
  604.     "#if !defined(__TListBoxRec)\n"
  605.     "#define __TListBoxRec\n"
  606.     "struct TListBoxRec\n"
  607.     "{\n"
  608.     "    TCollection* collection;\n"
  609.     "    short focused;\n"
  610.     "};\n"
  611.     "#endif\n\n";
  612.  
  613.    int first = True;
  614.    ScriptColl->forEach(doFields, &first);
  615.    if (!first) outf << "  };\n\n";  //if !first, there is at least one field
  616.    }
  617. }
  618.  
  619. void doVars(void *p, void*)
  620. {ViewObj *P = (ViewObj*)p;
  621.  P->writeVars();
  622. }
  623.  
  624. void doTheVars()
  625.  //define variables whose names are not "control"
  626. {
  627.  ScriptColl->forEach(doVars, 0);
  628.  outf << endl;
  629. }
  630.  
  631. void ancestorConstructor()
  632. {
  633.  outf << "       TDialog";
  634.  doTRect(Dialog);
  635.  outf << ", " << quoted(((DialogWriteObj*)(Dialog))->Title) << "),\n";
  636. }
  637.  
  638. void doUsesStuff()
  639. {
  640.  static char* uses[] = {"TDialog", "TButton", "TStaticText", "TColoredText",
  641.     "TInputLine", "TLabel", "THistory", "TInputLong", "TCheckBoxes",
  642.     "TRadioButtons", "TMultiCheckBoxes", "TListBox", "TMemo", "TScrollBar"};
  643.  
  644.  short ts = 0;
  645.  for (recType i = Button; i <= ScrollB; ((int)i)++)
  646.     if (present[i]) {
  647.        outf << "#define Uses_" << uses[i] << endl;
  648.        ts |= (i == CheckB || i == RadioB || i == MultiCB);
  649.        }
  650.  if (ts)
  651.     outf << "#define Uses_TSItem\n";
  652. }
  653.  
  654. void doLinks(void *p, void*)
  655. {char *P = (char*)p;
  656.  outf << "__link(R" << (char*)((P)+1) << ")\n";  //subst 'R' for 'T'
  657. }
  658.  
  659. void doIncludes()
  660. {
  661.   if (present[CText])
  662.     outf << "#include \"tcolortx.h\"\n";
  663.   if (present[ILong])
  664.     outf << "#include \"tinplong.h\"\n";
  665. }
  666.  
  667. //-------------------------------------------------------------------
  668. // The following exit procedure is required in order to view error
  669. // messages before Turbo Vision wipes out the screen
  670. //-------------------------------------------------------------------
  671. int exit_flag = 1;
  672.  
  673. void exitfunc(void)
  674. {
  675.   if( exit_flag )
  676.   {
  677.      cout << "\nStrike Enter key to continue" << endl;
  678.      char c;
  679.      cin.get(c);
  680.   }
  681. }
  682.  
  683. #pragma exit exitfunc  100
  684.  
  685. int main(int argc, char** argv)
  686. // argv[1] is script file
  687. // argv[2] is .src name
  688. // argv[3] is error filename
  689.  
  690. {
  691.  if (argc < 3) {
  692.    cout << "Usage:  cppsrc2 <script filename> <source filename> [error filename]";
  693.    exit(1);
  694.    }
  695.  if (argc >= 4) {
  696.    freopen(argv[3], "w", stdout);
  697.    exit_flag = 0;   // won't need hold up on exit
  698.    }
  699.  
  700.  checkMemory();
  701.  
  702.  data.open(SkelDatName(argv[0], s), ios::in);
  703.  if (!data.good()) {
  704.    cout << "Can't open cppskel.dat" << endl;
  705.    exit(1);
  706.    }
  707.  
  708.  readScriptFile(argv[1]);  //argv(1) is temporary script file
  709.  
  710.  outf.open(argv[2], ios::out);
  711.  if (!outf.good()) {
  712.    cout << "Can't open source file" << endl;
  713.    exit(1);
  714.    }
  715.  fnsplit(argv[2], 0, 0, upperName, 0);
  716.  strupr(upperName);            //for use later
  717.  strcpy(lowerName, upperName);
  718.  strlwr(lowerName);
  719.  
  720.  while (!data.eof()) {
  721.     data.getline(s, BIG);
  722.     if (strcmp(s, "@ZZ0") == 0) Dialog->writeCode();
  723.     else if (strcmp(s, "@ZZ1") == 0) doTheVars();
  724.     else if (strcmp(s, "@ZZ2") == 0) doTheDataStruct();
  725.     else if (strcmp(s, "@ZZ3") == 0) doTheReadItems();
  726.     else if (strcmp(s, "@ZZ4") == 0) doTheWriteItems();
  727.     else if (strcmp(s, "@ZZ5") == 0) ancestorConstructor();
  728.     else if (strcmp(s, "@ZZ6") == 0) doUsesStuff();
  729.     else if (strcmp(s, "@ZZ7") == 0) doIncludes();
  730.     else if (strcmp(s, "@ZZ8") == 0) classCollection->forEach(doLinks, 0);
  731.     else  {
  732.        char *p = strstr(s, "@XX");
  733.        while (p) {
  734.          subst(p);
  735.          p = strstr(s, "@XX");
  736.          }
  737.        outf << s << endl;
  738.        }
  739.     }
  740.  
  741.  outf.close();
  742.  data.close();
  743.  cout << "completed" << endl;
  744.  return 0;
  745. }
  746.